package cn.tedu.ivos.vehicle.service.impl;

import cn.tedu.ivos.vehicle.mapper.VehicleMapper;
import cn.tedu.ivos.vehicle.pojo.dto.VehicleQuery;
import cn.tedu.ivos.vehicle.pojo.dto.VehicleSaveParam;
import cn.tedu.ivos.vehicle.pojo.entity.Vehicle;
import cn.tedu.ivos.vehicle.pojo.vo.VehicleVO;
import cn.tedu.ivos.vehicle.service.VehicleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.Date;
import java.util.List;


@Slf4j
@Service
public class VehicleServiceImpl implements VehicleService {

    @Autowired
    private VehicleMapper vehicleMapper;
    /**
     * 查询车辆列表
     * @param vehicleQuery
     * @return
     */
    @Override
    public List<VehicleVO> list(VehicleQuery vehicleQuery) {
        log.debug("查询车辆列表，参数：{}",vehicleQuery);
        List<VehicleVO> list=vehicleMapper.list(vehicleQuery);
        return list;
    }

    /**
     * 新增操作and修改操作
     * @param vehicleSaveParam
     */
    @Override
    public void insert(VehicleSaveParam vehicleSaveParam) {
        log.debug("新增车辆信息，参数：{}",vehicleSaveParam);
        Vehicle vehicle=new Vehicle();
        BeanUtils.copyProperties(vehicleSaveParam,vehicle);
        if(vehicleSaveParam.getId()==null){
            vehicle.setCreateTime(new Date());
            vehicle.setStatus("1");
            vehicle.setGeofenceBindStatus("0");
            vehicleMapper.insert(vehicle);
        }else{
            //修改操作
            vehicle.setUpdateTime(new Date());
            vehicleMapper.update(vehicle);
        }
    }

    @Override
    public void delete(Long id) {
        log.debug("删除车辆信息，参数：{}",id);
        vehicleMapper.delete(id);
    }
}

